package net.sansi.v3correctserver.config.matrixloader;

import java.nio.ByteBuffer;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Fang
 * create time : 2024/11/8
 * IDE : IntelliJ IDEA
 * <p>
 * set long类型 加载器
 */

public class SetLongMatrixFileLoader extends MatrixFileLoaderBase<Set<Long>> {

    public SetLongMatrixFileLoader() {
        super(0);
    }

    @Override
    int getItemSize(Set<Long> item) {
        return item.size();
    }

    @Override
    int getItemBufferSize(Set<Long> item) {
        return getItemSize(item) * Long.BYTES;
    }

    @Override
    int getItemBufferSize(int len) {
        return 0;
    }

    @Override
    void saveItemBuffer(ByteBuffer buffer, Set<Long> item) throws Exception {
        for (long v : item) {
            buffer.putLong(v);
        }
    }

    @Override
    Set<Long> readItemBuffer(ByteBuffer buffer, int size) throws Exception {
        HashSet<Long> res = new HashSet<>();
        for (int i = 0; i < size; i++) {
            res.add(buffer.getLong());
        }
        return res;
    }

}
